library("NbClust")
library("rattle")


wssplot <- function(data, nc=5, seed=1234) {
  wss <- (nrow(data)-1)*sum(apply(data, 2, var))
  for (i in 2:nc) {
    set.seed(seed)
    wss[i] <- sum(kmeans(data, centers=i)$withinss)
  }
  plot(1:nc, wss, type="b", xlab="Number of Clusters", ylab="Within groups sum of squares")
}

data(wine, package="rattle")
head(wine)

df <- scale(wine[-1])

wssplot(df)

set.seed(1234)
# devAskNewPackage(ask=TRUE)
nc <- NbClust(df, min.nc=2, max.nc=15, method="kmeans")
table(nc$Best.n[1,])